<?php 
/**
 * CF
 *
 * @package CF
 * @version 0.1
 * @author Francesco Mantello
 */
class CF
{
	/**
	 * cache
	 *
	 * @param string $url
	 * @return string
	 */
	static public function cache($url, $file, $force = false) {
		if($force
		|| !file_exists($file)) {
			file_put_contents($file, self::get($url));
			// -----
		}
		 
		return file_get_contents($file);
		// -----
	}
	
	/**
	 * get
	 *
	 * @param string $url
	 * @return string
	 */
	static public function get($url) {
		$ch = curl_init();
		// -----
		
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		// -----
		
		$data = curl_exec($ch);
		// -----
		
		return self::clearParseString($data);
		// -----	
	}
	
	/**
	 * clearParseString
	 *
	 * @param string $string
	 * @return string
	 */
	static public function clearParseString($string) {
		$string = trim(preg_replace("'[\n\r\t\s]'", ' ', $string));
		$string = preg_replace("/\s\s+/", " ", trim($string));
		// -----
	
		return $string;
		// -----
	}
} 
?>